#include "RenzoMustHave.h"
#include "RenzoPrecompiled.h"
#include "RenzoTextureManager.h"
#include "RenzoImage.h"
#include "RenzoTexture.h"
#include "RenzoResourceManager.h"

namespace Renzo
{
TextureManager::TextureManager(void)
: maxTexID(0)
{
}

TextureManager::~TextureManager(void)
{
	for (TextureList::iterator i = textures.begin(); i != textures.end(); i++) {
		rzDel(i->second);
	}
	textures.clear();
}

Texture* TextureManager::createTexture(Image* img) {	
	Texture* t = 0;
	TextureList::iterator i;
	for (i = textures.begin(); i != textures.end(); i++) {
		if (i->second->getImage()->getID() == img->getID()) {
			return i->second;
		}
	}
	//t = new Texture(img);
	t = (Texture*)Renzoderer::instance()->getResourceManager()->createObject(TextureType);
	t->initialize(img);

	textures[t->getID()] = t;
	return t;
}

TexID TextureManager::genTexID() {
	return maxTexID++;
}

}
